//
//  LZMusicListTableViewCell.m
//  laziz_Merchant
//
//  Created by ZhaoDongBo on 2016/12/7.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZMusicListTableViewCell.h"

#import "Masonry.h"

@implementation LZMusicListTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
        self.contentView.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self configView];

        [self addAutoLayoutToCell];
    }
    return self;
}

- (void)configView {
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.musicImageView];
    [self.bgView addSubview:self.musicTitle];
    [self.bgView addSubview:self.musicArtist];
    [self.bgView addSubview:self.musicTrackView];
    [self.bgView addSubview:self.selectImageView];
}

- (void)addAutoLayoutToCell {
    
    WS(weakSelf);
    
    [self.bgView makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.trailing.mas_equalTo(-10);
    }];
    
    [self.musicImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(85, 85));
    }];
    
    [self.musicTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.leading.mas_equalTo(weakSelf.musicImageView.mas_trailing).with.offset(10);
        make.trailing.mas_equalTo(-12);
        make.height.mas_equalTo(15);
    }];
    
    [self.musicArtist mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.musicTitle.mas_bottom).with.offset(10);
        make.leading.mas_equalTo(weakSelf.musicImageView.mas_trailing).with.offset(10);
        make.trailing.mas_equalTo(-12);
        make.height.mas_equalTo(15);
    }];
    
    [self.musicTrackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(weakSelf.musicImageView.mas_trailing).with.offset(10);
        make.trailing.mas_equalTo(-12);
        make.bottom.mas_equalTo(-10);
        make.height.mas_equalTo(18.5);
    }];
    
    [self.selectImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.trailing.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(25, 25));
    }];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
}

- (UIView *)bgView {

    if (_bgView == nil) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor     = UIColorFromRGB(0x222222, 1);
        _bgView.layer.masksToBounds = YES;
        _bgView.layer.cornerRadius  = 4;
        _bgView.clipsToBounds       = NO;
    }
    
    return _bgView;
}

- (UIImageView *)musicImageView {
    
    if (_musicImageView == nil) {
        _musicImageView = [[UIImageView alloc] init];
    }
    
    return _musicImageView;
}

- (UILabel *)musicTitle {
    
    if (_musicTitle == nil) {
        _musicTitle = [[UILabel alloc] init];
        _musicTitle.textColor   = UIColorFromRGB(0x999999, 1);
        _musicTitle.font        = [UIFont systemFontOfSize:15];
    }
    
    return _musicTitle;
}

- (UILabel *)musicArtist {
    
    if (_musicArtist == nil) {
        _musicArtist = [[UILabel alloc] init];
        _musicArtist.textColor        = UIColorFromRGB(0x666666, 1);
        _musicArtist.font             = [UIFont systemFontOfSize:13];
    }
    
    return _musicArtist;
}

- (UIImageView *)musicTrackView {
    
    if (_musicTrackView == nil) {
        _musicTrackView = [[UIImageView alloc] init];
        _musicTrackView.image = [UIImage imageNamed:@"lz_musiclist_track"];
    }
    
    return _musicTrackView;
}

- (UIImageView *)selectImageView {

    if (_selectImageView == nil) {
        _selectImageView = [[UIImageView alloc] init];
        _selectImageView.image = [UIImage imageNamed:@"lz_musiclist_select"];
        _selectImageView.hidden = YES;
    }
    
    return _selectImageView;
}

@end
